package com.zhz.employee.biz;

import com.zhz.common.enums.BizResponseEnum;
import com.zhz.common.utils.ConvertUtils;
import com.zhz.employee.contract.request.EmployeeSavePersonalRequest;
import com.zhz.employee.contract.request.FindPersonalInfoRequest;
import com.zhz.employee.contract.response.FindPersonalInfoResponse;
import com.zhz.employee.repository.service.UserCompanyPersonalService;
import com.zhz.model.employee.contract.dto.UserCompanyPersonalDTO;
import com.zhz.model.employee.contract.param.UserCompanyPersonalQueryParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 企业信息详情
 *
 * @author zhouhengzhe
 * @date 2023/5/30
 */
@Component
public class UserCompanyPersonalBizService {

    private final UserCompanyPersonalService userCompanyPersonalService;

    @Autowired
    public UserCompanyPersonalBizService(UserCompanyPersonalService userCompanyPersonalService) {
        this.userCompanyPersonalService = userCompanyPersonalService;
    }

    /**
     * 根据ID获取企业信息详情
     *
     * @param id 主键ID
     * @return 企业信息详情
     */
    public UserCompanyPersonalDTO findById(String id) {
        //企业信息详情
        UserCompanyPersonalDTO userCompanyPersonalDTO = userCompanyPersonalService.get(id);
        BizResponseEnum.USER_COMPANY_PERSONAL_NOT_EXIST.assertNotNull(userCompanyPersonalDTO);
        return userCompanyPersonalDTO;
    }

    /**
     * 保存企业信息详情
     *
     * @param employeeSavePersonalRequest 企业信息
     * @param companyId                   公司ID
     */
    public void save(EmployeeSavePersonalRequest employeeSavePersonalRequest, String companyId) {
        UserCompanyPersonalDTO sourceInfo = ConvertUtils.sourceToTarget(employeeSavePersonalRequest, UserCompanyPersonalDTO.class);
        sourceInfo.setCompanyId(companyId);
        userCompanyPersonalService.save(sourceInfo);
    }


    /**
     * 员工个人信息模板
     *
     * @param findPersonalInfoRequest 员工个人信息模板请求
     * @return 员工个人信息模板响应
     */
    public FindPersonalInfoResponse findPersonalInfo(FindPersonalInfoRequest findPersonalInfoRequest) {
        UserCompanyPersonalDTO info = userCompanyPersonalService.getOne(
                UserCompanyPersonalQueryParam
                        .builder()
                        .id(findPersonalInfoRequest.getId())
                        .build()
        );
        BizResponseEnum.USER_PERSONAL_INFO_NOT_EXIST.assertNotNull(info);
        return ConvertUtils.sourceToTarget(info, FindPersonalInfoResponse.class);
    }
}
